//
//  M1CerViewController.m
//  NewMarryU
//
//  Created by apple on 2018/7/13.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1CerViewController.h"
#import "M1RealNameViewController.h"
#import "M1CerWebViewController.h"
@interface M1CerViewController ()
@property (nonatomic ,strong) UILabel *m1_numLB;
@end

@implementation M1CerViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    [M1User m1_uploadInfo:^(M1User *user) {
        if (user.status.auth_fees_status == 1) {
            [self.navigationController pushViewController:[M1RealNameViewController new] animated:YES];
        }
    }];
}
-(void)m1_commit{
    
    NSDictionary *params = @{@"channel":@"alipay_web",
                             @"id":@"6",
                             @"type":@"0",
                             @"amount":@"29.9"
                             };
    
    WEAKSELF;
    [M1HttpNet requestWithMethod:m1_create_order_url params:params success:^(id resDic, NSInteger code, NSString *message) {
        NSString *order_str = [resDic m1_stringKey:@"web_data"];
        M1CerWebViewController *m1_vc = [[M1CerWebViewController alloc]init];
        m1_vc.m1_jsHtml = order_str;
        [weakSelf.navigationController pushViewController:m1_vc animated:YES];
    } fail:^(id resDic, NSInteger code, NSString *message) {
        [M1Alert m1_alertWithTitle:nil message:message];
    } showAni:YES];

}
-(void)m1_back{
    WEAKSELF;
    [M1Alert m1_alertWithTitle:nil message:@"您确定要放弃加入MarryU吗？" buttonTitles:@[@"取消",@"确认"] action:^(NSInteger index) {
        if (index == 1) {
            NSArray *m1_vcs = weakSelf.navigationController.viewControllers;
            if ([m1_vcs[0] isKindOfClass:[M1ShuntVC class]]) {
                [weakSelf.navigationController popToRootViewControllerAnimated:YES];
            }else{
                NSInteger vcindex = 0;
                for (int i=0; i<m1_vcs.count; i++) {
                    if ([m1_vcs[i] isKindOfClass:[M1LoginVC class]]) {
                        vcindex = i;
                        break;
                    }
                }
                [M1User remove];
                [[EMClient sharedClient] logout:YES];
                [weakSelf.navigationController popToViewController:[m1_vcs objectAtIndex:vcindex-1] animated:YES];
            }
        }
        
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"付费认证";
    [self m1_banPopGesture];
    UIImageView *m1_imgView = [[UIImageView alloc]init];
    m1_imgView.image = [UIImage imageNamed:@"login_cer"];
    m1_imgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:m1_imgView];
    if (iPhone5) {
        [m1_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view.mas_centerX);
            make.top.offset(m1_NAV_HEIGHT);
            make.width.mas_offset(SCREENWIDTH-120);
            make.height.equalTo(m1_imgView.mas_width).multipliedBy(640/506.);
        }];
    }else{
        [m1_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view.mas_centerX);
            make.top.offset(m1_NAV_HEIGHT);
        }];
    }
    
    
    _m1_numLB = [[UILabel alloc]init];
    _m1_numLB.textColor = [UIColor m1_colorHex:0x323333];
    _m1_numLB.font = m1_font(15);
    _m1_numLB.text = @"位优质单身已付费认证身份等你来!";
    _m1_numLB.numberOfLines = 0;
    _m1_numLB.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_m1_numLB];
    [_m1_numLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.right.offset(-10);
        make.top.equalTo(m1_imgView.mas_bottom).offset(15);
    }];
    
    NSMutableAttributedString *m1_str = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@位优质单身已付费认证身份等你来!",[M1SaveTool m1_appConfig].user_count]];
    [m1_str addAttributes:@{NSForegroundColorAttributeName:[UIColor m1_colorHex:0xFF5A3F]} range:NSMakeRange(0, [[M1SaveTool m1_appConfig].user_count length])];
    _m1_numLB.attributedText = m1_str;
    
    UILabel *m1_LB1 = [[UILabel alloc]init];
    m1_LB1.textColor = [UIColor m1_colorHex:0x999999];
    m1_LB1.font = m1_font(12);
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:@"永久认证仅需 ¥109"];
    [str addAttributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle),NSStrikethroughColorAttributeName:[UIColor m1_colorHex:0x999999],NSFontAttributeName:m1_font(12)} range:NSMakeRange(6, 5)];
    m1_LB1.attributedText = str;
    [self.view addSubview:m1_LB1];
    [m1_LB1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(_m1_numLB.mas_bottom).offset(14);
    }];
    
    UILabel *m1_LB2 = [[UILabel alloc]init];
    m1_LB2.textColor = [UIColor m1_colorHex:0x333333];
    m1_LB2.font = m1_font(15);
    NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc]initWithString:@"限时2.7折 优惠: ¥29.9"];
    [str1 addAttributes:@{NSForegroundColorAttributeName:[UIColor m1_colorHex:0xFF5A3F]} range:NSMakeRange(2, 3)];
    m1_LB2.attributedText = str1;
    [self.view addSubview:m1_LB2];
    [m1_LB2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(m1_LB1.mas_bottom).offset(14);
    }];
    
    UIButton *m1_btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    m1_btn1.titleLabel.font = m1_font(14);
    [m1_btn1 setTitleColor:[UIColor whiteColor] forState:0];
    [m1_btn1 setTitle:@"为什么要缴纳认证费？" forState:0];
    m1_btn1.layer.cornerRadius = 11.5;
    [m1_btn1 addTarget:self action:@selector(m1_click) forControlEvents:UIControlEventTouchUpInside];
    m1_btn1.backgroundColor = [UIColor m1_colorHex:0xD0DAE8];
    [self.view addSubview:m1_btn1];
    
    [m1_btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(m1_LB2.mas_bottom).offset(20);
        make.size.mas_offset(CGSizeMake(158, 23));
    }];
    
    UIButton *m1_commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [m1_commitBtn setTitle:@"即刻认证" forState:0];
    [m1_commitBtn setBackgroundImage:[UIImage imageNamed:@"btn_color"]  forState:0];
    m1_commitBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [m1_commitBtn setTitleColor:[UIColor whiteColor] forState:0];
    m1_commitBtn.titleLabel.font = m1_font(16);
    m1_commitBtn.layer.cornerRadius = 25;
    m1_commitBtn.clipsToBounds = YES;
    [m1_commitBtn addTarget:self action:@selector(m1_commit) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:m1_commitBtn];
    [m1_commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(38);
        make.right.offset(-38);
        make.top.equalTo(m1_btn1.mas_bottom).offset(30);
        make.height.mas_offset(50);
    }];
}
-(void)m1_click{
    JCAlertStyle *style = [JCAlertStyle shareStyle];
    style.background.canDismiss = YES;
    style.background.autoDismiss = NO;
    
    UIView *m1_view = [[UIView alloc]init];
    m1_view.backgroundColor = [UIColor whiteColor];
    m1_view.layer.cornerRadius = 5;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitleColor:[UIColor m1_colorHex:0x333333] forState:0];
    [btn setTitle:@"X" forState:0];
    [m1_view addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-5);
        make.top.offset(5);
        make.size.mas_offset(CGSizeMake(20, 20));
    }];
    
    UILabel *m1_tv = [[UILabel alloc]init];
    m1_tv.textColor = [UIColor m1_colorHex:0x333333];
    m1_tv.font = m1_font(14);
    m1_tv.numberOfLines = 0;
    m1_tv.backgroundColor = [UIColor whiteColor];
    m1_tv.frame = CGRectMake(10, 25, style.alertView.width-20, 120);
    m1_tv.text = @"1、MarryU致力打造100%真实的平台，通过收取基本的认证费用可以筛选掉大部分的虚假用户。\n2、进行严格的身份认证需要耗费大量的人力成本，收取基本的认证费用可以保证MarryU持续稳定的运营。\n3、建立线下专属实名档案，可免费参加一次MarryU恋爱体验馆单身活动。";
    [m1_view addSubview:m1_tv];
    [m1_tv sizeToFit];
    m1_view.frame = CGRectMake(0, 0, style.alertView.width, m1_tv.bounds.size.height+35);
    JCAlertController *m1_alert = [JCAlertController alertWithTitle:nil contentView:m1_view];
    [self presentViewController:m1_alert animated:YES completion:nil];
    
    [btn m1_handler:^(UIButton *sender) {
        [m1_alert dismissViewControllerAnimated:YES completion:nil];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
